﻿// See https://aka.ms/new-console-template for more information
using System.Data;

//1.创建DataTable对象
DataTable userTable = new DataTable("user");
//2.定义列
userTable.Columns.Add("userId");
userTable.Columns.Add("userName");
userTable.Columns.Add("userAge");
//3.填充数据
userTable.Rows.Add(1,"小明",12);
userTable.Rows.Add(2, "小红", 11);
userTable.Rows.Add(3, "小光", 10);

DataRow dr = userTable.NewRow();
dr["userId"] = 4;
dr["userName"] = "小强";
dr["userAge"] = 9;
userTable.Rows.Add(dr);

//4.删数据
//userTable.Rows[1].Delete();

//5.改数据
//userTable.Rows[1][2] = 12;
userTable.Rows[1]["userAge"] = 13;

//6.查看数据
for(int i = 0; i < userTable.Rows.Count; i++)
{
    DataRow row=userTable.Rows[i];
    string userId = row["userId"].ToString();
    string userName = row["userName"].ToString();
    string userAge = row["userAge"].ToString();
    Console.WriteLine($"{userId}---{userName}---{userAge}");
}


Console.ReadLine();
